package fire.room;

import java.util.ArrayList;
import util.OOMLoad;

import jgame.JGObject;
import jgame.JGPoint;
import jgame.impl.EngineLogic;

import fire.Main;
import fire.chacracter.Player;
import fire.gui.LoadingScreen;

public class Map {
	private String tbl, oomFile;
	private int hTiles, vTiles;
	private JGPoint center = new JGPoint();
	private Player player;
	private int state = 0;
	private ArrayList<JGObject> oomList = new ArrayList<JGObject>();

	public Map(String tbl, String oomFile, int hTiles, int vTiles) {
		this.tbl = tbl;
		this.oomFile = oomFile;
		this.hTiles = hTiles;
		this.vTiles = vTiles;
	}
	
	public void createMap(Main main) {
		LoadingScreen l = new LoadingScreen("clone", 70, this);
		state = 0;
		main.defineMedia(tbl);
		main.setBGImage("background");
		main.setPFSize(hTiles, vTiles);
		OOMLoad.oomLoad(oomFile, oomList, main);
		player = main.getPlayer();
	}

	public JGPoint updateCenter() {
		switch (state) {
		case 0:
			center.x = -1488;
			center.y = 380;
			break;
		case 1:
			center.x = 683;
			center.y = 384;
			break;
		case 2:
			center.x = (int) player.x;
			center.y = (int) player.y;
			break;
		default:
			break;
		}
		return center;
	}

	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
	}

	public Player getPlayer() {
		return player;
	}

	public void setPlayer(Player player) {
		this.player = player;
	}

	public void updateView(Main main) {
		// set view port
		if (state != 0) {
			main.setViewOffset(updateCenter().x, updateCenter().y, true);
		} else {
			main.setview(updateCenter().x, updateCenter().y, true, true);
		}
	}
}